<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use App\Models\User;
use App\Models\Vippurchase;
use App\Models\GoldRecord;
use App\Models\GoldProduct;
use Brick\Math\RoundingMode;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
use Illuminate\Database\Eloquent\Collection;
use App\Services\MakeGoldRecord\MakeGoldRecord;
use App\Services\CloseUnpaidStorm\CloseUnpaidStorm;
use App\Jobs\MakeGoldRecordJob;
use App\Jobs\ApplyGoldProductPayingJob;
use App\Events\GoldRecordPaidEvent;


class Test extends Command
{
    protected $signature = 'cc:test';

    protected $description = "";

    public function handle()
    {

        $vips = Vippurchase::query()->where("paid_method","=","card")->whereNotNull("paid_at")->where('user_id',2258745)->get();
        //2255347,2258570
        foreach($vips as $vip){

            $vipExpiredAt = Carbon::now()->addDays(cs('sale')->vip_period)->hours(23)->minutes(59)->seconds(59);
                
            $vip->user->upgradeLogs()->create([
                'reason' => '付费升级为VIP会员',
                'vip_expired_at' => $vipExpiredAt
            ]);
            
            $vip->user->update([
                'grade' => 'vip',
                'grade_level' => 0,
                'vip_expired_at' => $vipExpiredAt,
                'rewarded_at'=>time(),
            ]);
        }
       
    }
}
